package top.infopub.mgr.sys.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import top.infopub.common.ErrorCodeEnum;
import top.infopub.generic.GenericController;
import top.infopub.mgr.common.cnst.Constants;
import top.infopub.mgr.util.ZKPathsUtil;
import top.infopub.mgr.util.ZKPathsUtil.Zkpath;
import top.infopub.vo.ResponseVo;


/**
 * 设置Zookeeper各缓存节点的[同步数据]
 * @author Awoke
 * @version 2018年10月15日
 * @see ZkpPathController
 * @since
 */
@Controller
@RequestMapping("/zkpPath")
public class ZkpPathController extends GenericController {

    @Autowired
    private ZKPathsUtil zkpathsUtil;

    /**
     * 数据字典 节点
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/dataDic")
    public @ResponseBody ResponseVo zkpDataDict() {
        if (zkpathsUtil.createrOrUpdate(Zkpath.dataDic)) {
            return ResponseVo.getSuccessMsgResponse(Constants.REFRESH_CACHE_SUCCESS);
        }
        else {
            return ErrorCodeEnum.ERROR_COMMON_SYSTEM.getResponseVo("ZooKeeper节点发起设置失败！");
        }
    }

    /**
     * 业务参数 节点
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/bizParameter")
    public @ResponseBody ResponseVo zkpBusinessParameterService() {
        if (zkpathsUtil.createrOrUpdate(Zkpath.bizParameter)) {
            return ResponseVo.getSuccessMsgResponse(Constants.REFRESH_CACHE_SUCCESS);
        }
        else {
            return ErrorCodeEnum.ERROR_COMMON_SYSTEM.getResponseVo("ZooKeeper节点发起设置失败！");
        }
    }

    /**
     * 后台权限 节点
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/operatorPurview")
    public @ResponseBody ResponseVo zkpOperatorPurviewNotice() {
        if (zkpathsUtil.createrOrUpdate(Zkpath.operatorPurview)) {
            return ResponseVo.getSuccessMsgResponse(Constants.REFRESH_CACHE_SUCCESS);
        }
        else {
            return ErrorCodeEnum.ERROR_COMMON_SYSTEM.getResponseVo("ZooKeeper节点发起设置失败！");
        }
    }

    /**
     * 前台会员权限 节点
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/frontPurview")
    public @ResponseBody ResponseVo zkpFrontPurviewNotice() {
        if (zkpathsUtil.createrOrUpdate(Zkpath.frontPurview)) {
            return ResponseVo.getSuccessMsgResponse(Constants.REFRESH_CACHE_SUCCESS);
        }
        else {
            return ErrorCodeEnum.ERROR_COMMON_SYSTEM.getResponseVo("ZooKeeper节点发起设置失败！");
        }
    }

    /**
     * 消息服务提供商 节点
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/mgcPartnerInfo")
    public @ResponseBody ResponseVo zkpMgcPartnerInfo() {
        if (zkpathsUtil.createrOrUpdate(Zkpath.mgcPartnerInfo)) {
            return ResponseVo.getSuccessMsgResponse(Constants.REFRESH_CACHE_SUCCESS);
        }
        else {
            return ErrorCodeEnum.ERROR_COMMON_SYSTEM.getResponseVo("ZooKeeper节点发起设置失败！");
        }
    }
    
    /**
     * 消息模板 节点
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/mgcTemplate")
    public @ResponseBody ResponseVo zkpMgcTemplate() {
        if (zkpathsUtil.createrOrUpdate(Zkpath.mgcTemplate)) {
            return ResponseVo.getSuccessMsgResponse(Constants.REFRESH_CACHE_SUCCESS);
        }
        else {
            return ErrorCodeEnum.ERROR_COMMON_SYSTEM.getResponseVo("ZooKeeper节点发起设置失败！");
        }
    }
    
    /**
     * 节日节点
     * @return
     */
    @SuppressWarnings("rawtypes")
    @RequestMapping("/holiday")
    public @ResponseBody ResponseVo zpkHoliday() {
        if(zkpathsUtil.createrOrUpdate(Zkpath.holiday)){
            return ResponseVo.getSuccessMsgResponse(Constants.REFRESH_CACHE_SUCCESS);
        }else{
            return ErrorCodeEnum.ERROR_COMMON_SYSTEM.getResponseVo("ZooKeeper节点发起设置失败！");
        } 
    }
}
